<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>账单导入 - 智能财务分析平台</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        /* 导入页面专属样式 */
        .import-container {
            max-width: 900px;
            margin: 0 auto;
            padding: 20px;
        }

        .import-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .import-header h1 {
            font-size: 28px;
            color: #333;
            margin-bottom: 10px;
        }

        .import-header p {
            color: #666;
            font-size: 14px;
        }

        .platform-selector {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .platform-selector label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #333;
        }

        .platform-selector select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .upload-area {
            background: white;
            border: 2px dashed #4CAF50;
            border-radius: 10px;
            padding: 50px 40px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
            margin-bottom: 20px;
        }

        .upload-area:hover {
            background: #f0f9f0;
            border-color: #45a049;
        }

        .upload-area.dragover {
            background: #e8f5e9;
            border-color: #2e7d32;
            transform: scale(1.02);
        }

        .upload-icon {
            font-size: 48px;
            margin-bottom: 15px;
        }

        .upload-text {
            font-size: 16px;
            color: #333;
            margin-bottom: 10px;
        }

        .upload-hint {
            color: #666;
            font-size: 14px;
        }

        .progress-container {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            display: none;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .progress-bar {
            width: 100%;
            height: 30px;
            background: #f0f0f0;
            border-radius: 15px;
            overflow: hidden;
            position: relative;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #4CAF50, #45a049);
            transition: width 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 14px;
            font-weight: 500;
        }

        .progress-text {
            margin-top: 10px;
            text-align: center;
            color: #666;
            font-size: 14px;
        }

        .preview-container {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            display: none;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .preview-container h3 {
            margin-bottom: 15px;
            color: #333;
        }

        .preview-table-wrapper {
            max-height: 400px;
            overflow-y: auto;
            border: 1px solid #ddd;
            border-radius: 5px;
        }

        .preview-table {
            width: 100%;
            border-collapse: collapse;
        }

        .preview-table th,
        .preview-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        .preview-table th {
            background: #f5f5f5;
            font-weight: 500;
            position: sticky;
            top: 0;
            z-index: 1;
        }

        .preview-table tr:hover {
            background: #f9f9f9;
        }

        .income {
            color: #4CAF50;
        }

        .expense {
            color: #f44336;
        }

        .action-buttons {
            text-align: center;
            margin-top: 20px;
        }

        .btn {
            padding: 12px 30px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s;
            margin: 0 10px;
        }

        .btn-primary {
            background: #4CAF50;
            color: white;
        }

        .btn-primary:hover {
            background: #45a049;
        }

        .btn-secondary {
            background: #f0f0f0;
            color: #333;
        }

        .btn-secondary:hover {
            background: #e0e0e0;
        }

        .history-container {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-top: 30px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .history-container h3 {
            margin-bottom: 15px;
            color: #333;
        }

        .history-table {
            width: 100%;
            border-collapse: collapse;
        }

        .history-table th,
        .history-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        .history-table th {
            background: #f5f5f5;
            font-weight: 500;
        }

        .status-badge {
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 500;
        }

        .status-completed {
            background: #e8f5e9;
            color: #4CAF50;
        }

        .status-processing {
            background: #fff3e0;
            color: #ff9800;
        }

        .status-failed {
            background: #ffebee;
            color: #f44336;
        }

        .help-section {
            background: #e3f2fd;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
        }

        .help-section h4 {
            color: #1976d2;
            margin-bottom: 10px;
        }

        .help-section ul {
            margin: 10px 0;
            padding-left: 20px;
        }

        .help-section li {
            margin: 5px 0;
            color: #666;
        }

        .empty-state {
            text-align: center;
            padding: 40px;
            color: #999;
        }

        .empty-state-icon {
            font-size: 48px;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="import-container">
        <!-- 页面标题 -->
        <div class="import-header">
            <h1>📥 账单导入</h1>
            <p>支持微信、支付宝账单多种格式导入，自动去重、智能分类</p>
        </div>

        <!-- 使用说明 -->
        <div class="help-section">
            <h4>📖 使用说明</h4>
            <ul>
                <li><strong>微信账单导出：</strong>打开微信 → 我 → 服务 → 钱包 → 账单 → 常见问题 → 下载账单（支持CSV、Excel格式）</li>
                <li><strong>支付宝账单导出：</strong>打开支付宝 → 我的 → 账单 → 右上角 → 开具交易流水证明（支持CSV、Excel、PDF格式）</li>
                <li><strong>支持格式：</strong><span style="color: #4CAF50; font-weight: 500;">CSV、XLS、XLSX、PDF</span> - 最大10MB</li>
                <li><strong>自动处理：</strong>系统会自动识别格式、去重、智能分类，无需手动整理</li>
            </ul>
        </div>

        <!-- 平台和账本选择 -->
        <div class="platform-selector">
            <label for="platform">选择平台</label>
            <select id="platform">
                <option value="wechat">微信支付</option>
                <option value="alipay">支付宝</option>
                <option value="bank" disabled>银行卡（即将支持）</option>
            </select>

            <label for="bookId">选择账本</label>
            <select id="bookId">
                <option value="">加载中...</option>
            </select>
        </div>

        <!-- 上传区域 -->
        <div class="upload-area" id="uploadArea">
            <div class="upload-icon">📄</div>
            <div class="upload-text">拖拽账单文件到此处，或点击选择文件</div>
            <div class="upload-hint">
                支持格式：
                <span style="color: #2196F3;">CSV</span>、
                <span style="color: #217346;">XLS/XLSX</span>、
                <span style="color: #f44336;">PDF</span>
                （最大10MB）
            </div>
            <input type="file" id="fileInput" accept=".csv,.xls,.xlsx,.pdf" style="display: none;">
        </div>

        <!-- 进度条 -->
        <div class="progress-container" id="progressContainer">
            <div class="progress-bar">
                <div class="progress-fill" id="progressFill">0%</div>
            </div>
            <div class="progress-text" id="progressText">准备上传...</div>
        </div>

        <!-- 数据预览 -->
        <div class="preview-container" id="previewContainer">
            <h3>数据预览（前10条）</h3>
            <div class="preview-table-wrapper">
                <table class="preview-table">
                    <thead>
                        <tr>
                            <th>时间</th>
                            <th>类型</th>
                            <th>商户</th>
                            <th>描述</th>
                            <th>金额</th>
                        </tr>
                    </thead>
                    <tbody id="previewTableBody">
                    </tbody>
                </table>
            </div>
            <div class="action-buttons">
                <button class="btn btn-primary" onclick="confirmImport()">确认导入</button>
                <button class="btn btn-secondary" onclick="cancelImport()">取消</button>
            </div>
        </div>

        <!-- 导入历史 -->
        <div class="history-container">
            <h3>📊 导入历史</h3>
            <div id="historyContent">
                <div class="empty-state">
                    <div class="empty-state-icon">📋</div>
                    <div>暂无导入记录</div>
                </div>
            </div>
        </div>
    </div>

    <script src="js/api.js"></script>
    <script src="js/import-page.js"></script>
</body>
</html>

